package com.elai.web.controller.baseconfig;

import com.elai.common.annotation.Log;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.core.page.TableDataInfo;
import com.elai.common.enums.BusinessType;
import com.elai.common.utils.poi.ExcelUtil;
import com.elai.baseconfig.domain.EventMethodDO;
import com.elai.baseconfig.service.EventMethodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 事件函数Controller
 *
 * @author elai
 * @date 2021-05-05
 */
@RestController
@RequestMapping("/config/emethod")
public class EventMethodController extends BaseController
{
    @Autowired
    private EventMethodService eventMethodService;

    /**
     * 查询事件函数列表
     */
    @PreAuthorize("@ss.hasPermi('config:emethod:list')")
    @GetMapping("/list")
    public TableDataInfo list(EventMethodDO eventMethod)
    {
        startPage();
        List<EventMethodDO> list = eventMethodService.selectEventMethodList(eventMethod);
        return getDataTable(list);
    }


    @GetMapping("/getEventMethodList")
    public AjaxResult getEventMethodList(EventMethodDO eventMethod)
    {
        List<EventMethodDO> list = eventMethodService.selectEventMethodList(eventMethod);
        return AjaxResult.success(list);
    }

    /**
     * 导出事件函数列表
     */
    @PreAuthorize("@ss.hasPermi('config:emethod:export')")
    @Log(title = "事件函数", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EventMethodDO eventMethod)
    {
        List<EventMethodDO> list = eventMethodService.selectEventMethodList(eventMethod);
        ExcelUtil<EventMethodDO> util = new ExcelUtil<EventMethodDO>(EventMethodDO.class);
        return util.exportExcel(list, "emethod");
    }

    /**
     * 获取事件函数详细信息
     */
    @PreAuthorize("@ss.hasPermi('config:emethod:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(eventMethodService.selectEventMethodById(id));
    }

    /**
     * 新增事件函数
     */
    @PreAuthorize("@ss.hasPermi('config:emethod:add')")
    @Log(title = "事件函数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EventMethodDO eventMethod)
    {
        return toAjax(eventMethodService.insertEventMethod(eventMethod));
    }

    /**
     * 修改事件函数
     */
    @PreAuthorize("@ss.hasPermi('config:emethod:edit')")
    @Log(title = "事件函数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EventMethodDO eventMethod)
    {
        return toAjax(eventMethodService.updateEventMethod(eventMethod));
    }

    /**
     * 删除事件函数
     */
    @PreAuthorize("@ss.hasPermi('config:emethod:remove')")
    @Log(title = "事件函数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eventMethodService.deleteEventMethodByIds(ids));
    }
}
